package com.saunter.utils;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Util {
    public static Boolean equalList(List<String> list1, List<String> list2) {
        //list1.removeAll(list2)实现
        int list_length = list1.size();
        if(list_length > 0 && list_length == list2.size()) {
            Comparator<String> stringComparator = new Comparator<String>() {
                @Override
                public int compare(String s1, String s2) {
                    return s1.compareTo(s2);
                }
            };
            Collections.sort(list1, stringComparator);
            Collections.sort(list2, stringComparator);
            return list1.equals(list2);
        }else {
            return false;
        }
    }
    public static Boolean verifyPasswordFormat(String password) {
        if(null == password) return false;
        Matcher matcher_char = Pattern.compile("[a-zA-Z]+").matcher(password);
        Matcher matcher_num = Pattern.compile("\\d+").matcher(password);
        return 8 <= password.length() && matcher_char.find() && matcher_num.find();
    }
    public static Boolean verifyEmail(String email) {
        return null != email && Pattern.matches("^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z0-9]{2,6}$", email);
    }
    public static Boolean verifyPhone(String phone) {
        return null != phone && Pattern.matches("^(0|86|17951)?(19[0-9]|16[0-9]|13[0-9]|15[012356789]|17[0-9]|18[0-9]|14[57])[0-9]{8}$", phone);
    }
}
